﻿Public Class ucEstoqueLocalCadastro
#Region "Eventos públicos acessados pelo formulário de cadastro"
    Public Event Salvo()
    Public Event Cancelado()
#End Region

#Region "Estoque Local"
    Public Sub Novo()
        ' Da um new no model.pessoa
        bsEstoqueLocal.AddNew()
        LoadEstoqueLocal()
        StatusForm(True)
    End Sub

    Public Sub Visualiza(ByVal estoquelocal As Model.EstoqueLocal)
        StatusForm(False)

        Dim ctEstoqueLocal As New Control.EstoqueLocal

        bsEstoqueLocal.DataSource = ctEstoqueLocal.GetById(estoquelocal.cd_estoque_local)

        LoadEstoqueLocal()

    End Sub

    Private Sub Salvar()
        Dim EstoqueLocal As Model.EstoqueLocal
        Dim ControlEstoqueLocal As New Control.EstoqueLocal

        bsEstoqueLocal.EndEdit()
        EstoqueLocal = CType(bsEstoqueLocal.Current, Model.EstoqueLocal)

        ControlEstoqueLocal.Salvar(EstoqueLocal)

        ControlEstoqueLocal = Nothing

        StatusForm(False)

        ' Avisa o form pricipal que salvou para retornar a pesquisa
        RaiseEvent Salvo()

    End Sub

    Private Sub Cancelar()
        bsEstoqueLocal.CancelEdit()

        StatusForm(False)

        ' Avisa o form pricipal que cancelou para retornar a pesquisa
        RaiseEvent Cancelado()

    End Sub

    Private Sub Editar()
        StatusForm(True)
    End Sub


    ''' <summary>
    ''' Carrega os combos
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub LoadEstoqueLocal()

    End Sub

    ''' <summary>
    ''' Controla a ativação dos obj no formulário
    ''' </summary>
    ''' <param name="Status"></param>
    ''' <remarks></remarks>
    Private Sub StatusForm(ByVal Status As Boolean)
        pnlEstoqueLocal.Enabled = Status
        btnSalvar.Enabled = Status
        btnEditar.Enabled = Not Status
    End Sub
#End Region

#Region "Métodos dos objetos do formulário"
    Private Sub btnSalvar_Click(sender As Object, e As EventArgs) Handles btnSalvar.Click
        Salvar()
    End Sub

    Private Sub btnEditar_Click(sender As Object, e As EventArgs) Handles btnEditar.Click
        Editar()
    End Sub

    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        Cancelar()
    End Sub
#End Region

End Class
